<template>
	<view class="page-body">
		<!-- 页面内容开始 -->

		<!-- 表格搜索组件开始 -->
		<vk-data-table-query v-model="queryForm1.formData" :columns="queryForm1.columns" @search="search">
		</vk-data-table-query>
		<!-- 表格搜索组件结束 -->

		<!-- 自定义按钮区域开始 -->
		<view>
			<el-row>
				<el-button type="success" size="small" icon="el-icon-circle-plus-outline" @click="addBtn">添加</el-button>
				<!-- 批量操作 -->
			</el-row>
		</view>
		<!-- 自定义按钮区域结束 -->

		<!-- 表格组件开始 -->
		<vk-data-table ref="table1" :action="table1.action" :columns="table1.columns" :query-form-param="queryForm1"
			:right-btns="['detail_auto', 'update', 'delete']" :selection="false" :row-no="true" :pagination="true"
			:stripe="true" @update="updateBtn" @delete="deleteBtn" @current-change="currentChange"
			@selection-change="selectionChange">
		</vk-data-table>
		<!-- 表格组件结束 -->

		<!-- 添加或编辑的弹窗开始 -->
		<vk-data-dialog v-model="form1.props.show" :title="form1.props.title" width="500px" mode="form"
			:close-on-click-modal="false">
			<vk-data-form v-model="form1.data" :rules="form1.props.rules" :action="form1.props.action"
				:form-type="form1.props.formType" :columns='form1.props.columns' label-width="150px"
				@success="form1.props.show = false; refresh();">
				<template v-slot:footer="{ loading }">
					<view style="text-align: center;">
						<el-button :loading="loading" type="danger" style="padding: 10px 40px;margin-right: 30px; "
							@click="form1.props.show = false"> 取消 </el-button>
						<el-button :loading="loading" type="success" style="padding: 10px 40px; "
							@click="batchAdd(form1.data)"> 确定
						</el-button>
					</view>
				</template>
			</vk-data-form>
		</vk-data-dialog>
		<!-- 添加或编辑的弹窗结束 -->

		<!-- 页面内容结束 -->
	</view>
</template>

<script>
var that; // 当前页面对象
var vk = uni.vk; // vk实例
var originalForms = {}; // 表单初始化数据

export default {
	data() {
		// 页面数据变量
		return {
			// 页面是否请求中或加载中
			loading: false,
			// init请求返回的数据
			data: {

			},
			// 表格相关开始 -----------------------------------------------------------
			table1: {
				// 表格数据请求地址
				action: "admin/pages/kh/xcxpz/xcxgl/getList",
				// 表格字段显示规则
				columns: [

					{
						key: "",
						title: "小程序信息",
						type: "group",
						minWidth: 300,
						align: "left",
						columns: [{
							"key": "originid",
							"title": "小程序原始ID",
							"type": "text",
							"defaultValue": "未绑定"
						},
						{
							"key": "appid",
							"title": "appid",
							"type": "text",
							"defaultValue": "未绑定"
						},
						{
							"key": "appname",
							"title": "小程序名称",
							"type": "text",
							"defaultValue": "未绑定"
						},
						{
							"key": "appsecret",
							"title": "appsecret",
							"type": "text"
						},
						{
							"key": "pid",
							"title": "小程序绑定pid",
							"type": "text"
						},
						],
					},
					{
						key: "",
						title: "订阅消息模板",
						type: "group",
						minWidth: 300,
						align: "left",
						columns: [{
							"key": "xspsx",
							"title": "新剧上线提醒模板ID",
							"type": "text"
						},
						{
							"key": "flhd",
							"title": "签到提醒模板ID",
							"type": "text"
						},
						{
							"key": "jjgx",
							"title": "剧集更新提醒模板ID",
							"type": "text"
						},
						]
					},
					{
						key: "",
						title: "公众号和企微",
						type: "group",
						minWidth: 260,
						align: "left",
						columns: [{
							"key": "gzhurl",
							"title": "跳转公众号链接",
							"type": "text"
						},
						{
							"key": "workwxappid",
							"title": "企业微信appid",
							"type": "text"
						},
						{
							"key": "workwxurl",
							"title": "企业微信客服链接",
							"type": "text"
						},
						]
					},
					{
						key: "",
						title: "小程序相关配置",
						type: "group",
						minWidth: 260,
						align: "left",
						columns: [{
							"key": "opensearch",
							"title": "首页搜索开关",
							"type": "switch"
						},
						{
							"key": "staticInvite_code",
							"title": "静态邀请码开关",
							"type": "switch"
						},
						{
							"key": "beannumber",
							"title": "邀请奖励金豆数",
							"type": "number"
						},
						{
							"key": "signin_reward",
							"title": "签到奖励金豆数",
							"type": "number"
						},
						]
					},
					{
						key: "",
						title: "小程序首页相关配置",
						type: "group",
						minWidth: 260,
						align: "left",
						columns: [{
							"key": "twoInRow",
							"title": "首页一行两个视频",
							"type": "switch"
						},
						{
							"key": "iospay",
							"title": "是否允许ios用户充值",
							"type": "switch"
						},
						{
							"key": "index_tips_switch",
							"title": "首页提示语开关",
							"type": "switch"
						},
						{
							"key": "index_tips_text",
							"title": "首页提示语文字",
							"type": "text"
						},
						{
							"key": "tgemail",
							"title": "投稿邮箱",
							"type": "text"
						},
						]
					},
					{
						key: "",
						title: "其他页面相关配置",
						type: "group",
						minWidth: 260,
						align: "left",
						columns: [{
							"key": "gzhTip",
							"title": "追剧页提示语开关",
							"type": "switch"
						},
						{
							"key": "gzhTipText",
							"title": "追剧页提示语文字",
							"type": "text"
						},
						{
							"key": "tips_switch",
							"title": "播放页提示语开关",
							"type": "switch"
						},
						{
							"key": "tips_text",
							"title": "播放页提示语文字",
							"type": "text"
						},
						{
							"key": "gzgzh_tip",
							"title": "关注公众号提示语",
							"type": "text"
						},
						]
					},
					{
						key: "",
						title: "激励视频广告配置",
						type: "group",
						minWidth: 300,
						align: "left",
						columns: [{
							"key": "wxad_switch",
							"title": "激励视频广告开关",
							"type": "switch"
						},
						{
							"key": "wxad_adid",
							"title": "激励视频广告ID",
							"type": "text"
						},
						{
							"key": "wxad_maxlimit",
							"title": "每人每天最多几次",
							"type": "number"
						},
						{
							"key": "wxad_reward",
							"title": "单次奖励金豆数",
							"type": "number"
						},
						]
					},
					{
						"key": "wxad_rule",
						"title": "广告页面弹窗图片",
						"type": "image",
						"width": 200
					},
					{
						"key": "qrurl",
						"title": "客服二维码海报",
						"type": "image",
						"width": 200
					},

					// { "key": "dycodeSwitch", "title": "抖音口令开关", "type": "switch", "width": 200 },
					// { "key": "dycode", "title": "抖音视频分享口令", "type": "text", "width": 200 },
					{
						"key": "remark",
						"title": "备注",
						"type": "text",
						"width": 200
					},
					{
						"key": "add_time",
						"title": "添加时间",
						"type": "time",
						"width": 200
					}
				],
				// 多选框选中的值
				multipleSelection: [],
				// 当前高亮的记录
				selectItem: ""
			},
			// 表格相关结束 -----------------------------------------------------------
			// 表单相关开始 -----------------------------------------------------------
			// 查询表单请求数据
			queryForm1: {
				// 查询表单数据源，可在此设置默认值
				formData: {

				},
				// 查询表单的字段规则 fieldName:指定数据库字段名,不填默认等于key
				columns: [{
					"key": "appid",
					"title": "appid",
					"type": "text",
					"width": 200,
					"mode": "="
				},
				{
					"key": "appname",
					"title": "小程序名称",
					"type": "text",
					"width": 200,
					"mode": "%%"
				},
				{
					"key": "remark",
					"title": "备注",
					"type": "text",
					"width": 200,
					"mode": "%%"
				}
				]
			},
			form1: {
				// 表单请求数据，此处可以设置默认值
				data: {
					recharge_instructions: "1.金豆币及会员权益，属于虚拟产品，一经购买不可退换2.末满18周岁的未成年人，应在父母或其他监护人的监护、指导、同意下进行付费等相关操作3.如有疑问，请联系客服",
					opensearch: false, //首页搜索框默认关闭
					staticInvite_code: true, //静态邀请码开关
					beannumber: 100, //邀请新用户默认100金豆
					signin_reward: 30, //签到默认30金豆
					index_tips_switch: true, //index页面右上角提示语开关
					index_tips_text: "点击···添加到桌面,下次看剧更方便", //index页面右上角提示语
					tips_switch: true, //player页面右上角提示语开关
					tips_text: "长按视频画面,拖动可快进", //player页面右上角提示语
					gzgzh_tip: "关注公众号，剧情抢先看",
					gzhTip: true,
					gzhTipText: "关注公众号获取更新通知~",
					twoInRow: true,
					freeBean: 0,
					receiveTime: 0,
					payMoney: 0,
					iospay: true,
					simplified:false
				},
				// 表单属性
				props: {
					// 表单请求地址
					action: "",
					// 表单字段显示规则
					columns: [{
						"key": "originid",
						"title": "小程序原始ID",
						"type": "text",
						"width": 400,
						"tips": "如果使用百度广告，此处必填"
					},
					{
						"key": "appid",
						"title": "appid",
						"type": "text",
						"width": 400
					},
					{
						"key": "appname",
						"title": "小程序名称",
						"type": "text",
						"width": 400
					},
					{
						"key": "appsecret",
						"title": "appsecret",
						"type": "text",
						"width": 400
					},
					{
						"key": "pid",
						"title": "小程序绑定pid",
						"type": "text",
						"width": 400,
						"tips": "此处仅供备注使用"
					},
					{
						"key": "iospay",
						"title": "是否允许ios用户充值",
						"type": "switch",
						"width": 150,
						"tips": "一般情况下打开，当被微信查到IOS支付违规时请关闭"
					},
					{
						"key": "gzhurl",
						"title": "跳转公众号链接",
						"type": "text",
						"width": 400,
						"tips": "仅微信小程序有效"
					},
					{
						"key": "workwxappid",
						"title": "企业微信appid",
						"type": "text",
						"width": 200,
						"tips": "仅微信小程序有效"
					},
					{
						"key": "workwxurl",
						"title": "企业微信客服链接",
						"type": "text",
						"width": 400,
						"tips": "仅微信小程序有效"
					},
					{
						"key": "qrurl",
						"title": "客服二维码海报",
						"type": "file-select",
						"placeholder": "请选择图片",
						"fileType": "image",
						"limit": 1,
						"tips": "需自行设计海报样式，可参考如下：https://hddj2022.oss-cn-hangzhou.aliyuncs.com/0images/qrurl.jpg"
					},
					{
						"key": "opensearch",
						"title": "首页搜索开关",
						"type": "switch",
						"width": 200
					},
					{
						"key": "staticInvite_code",
						"title": "静态邀请码开关",
						"type": "switch",
						"width": 200,
						"tips": "开启后用户的邀请码始终不变"
					},
					{
						"key": "beannumber",
						"title": "邀请奖励金豆数",
						"type": "number",
						"width": 200,
						"tips": "普通用户邀请一个新用户获得金豆数量"
					},
					{
						"key": "signin_reward",
						"title": "签到奖励金豆数",
						"type": "number",
						"width": 200,
						"tips": "用户签到一次获得金豆数量"
					},
					{
						"key": "",
						"title": "↓↓↓微信小程序订阅消息模板配置↓↓↓",
						"type": "bar-title"
					},
					{
						"key": "xspsx",
						"title": "新剧上线提醒模板ID",
						"type": "text",
						"width": 400
					},
					{
						"key": "flhd",
						"title": "签到提醒模板ID",
						"type": "text",
						"width": 400
					},
					{
						"key": "jjgx",
						"title": "剧集更新提醒模板ID",
						"type": "text",
						"width": 400
					},
					{
						"key": "",
						"title": "↓↓↓小程序追剧页面相关配置↓↓↓",
						"type": "bar-title"
					},
					{
						"key": "gzhTip",
						"title": "追剧页关注公众号提示开关",
						"type": "switch",
						"width": 400
					},
					{
						"key": "gzhTipText",
						"title": "追剧页关注公众号提示文字",
						"type": "text",
						"width": 400
					},
					{
						"key": "",
						"title": "↓↓↓小程序首页相关配置↓↓↓",
						"type": "bar-title"
					},
					{
						"key": "twoInRow",
						"title": "首页一行两个视频",
						"type": "switch",
						"tips": "关闭则一行3个视频"
					},
					{
						"key": "index_tips_switch",
						"title": "首页提示语开关",
						"type": "switch",
						"width": 400
					},
					{
						"key": "index_tips_text",
						"title": "首页提示语文字",
						"type": "text",
						"width": 400
					},
					{
						"key": "tgemail",
						"title": "投稿邮箱",
						"type": "text",
						"width": 200,
						"tips": "仅微信小程序有效"
					},
					{
						"key": "",
						"title": "↓↓↓播放页相关配置↓↓↓",
						"type": "bar-title"
					},
					{
						"key": "tips_switch",
						"title": "播放页提示语开关",
						"type": "switch",
						"width": 400
					},
					{
						"key": "tips_text",
						"title": "播放页提示语文字",
						"type": "text",
						"width": 400
					},
					{
						"key": "gzgzh_tip",
						"title": "关注公众号提示语",
						"type": "text",
						"width": 400
					},
					{
						"key": "",
						"title": "↓↓↓微信流量主广告配置↓↓↓",
						"type": "bar-title"
					},
					{
						"key": "wxad_switch",
						"title": "激励视频广告开关",
						"type": "switch",
						"width": 400
					},
					{
						"key": "wxad_adid",
						"title": "激励视频广告ID",
						"type": "text",
						"width": 400
					},
					{
						"key": "wxad_maxlimit",
						"title": "每人每天最多几次",
						"type": "number",
						"width": 400
					},
					{
						"key": "wxad_reward",
						"title": "单次奖励金豆数",
						"type": "number",
						"width": 400
					},
					{
						"key": "wxad_rule",
						"title": "广告页面弹窗图片",
						"type": "file-select",
						"placeholder": "请选择图片",
						"fileType": "image",
						"limit": 1,
						"tips": "一般是看广告获得奖励的相关规则，可参考:https://hddj2022.oss-cn-hangzhou.aliyuncs.com/0images/rules.png"
					},
					{
						"key": "remark",
						"title": "备注",
						"type": "text",
						"width": 400
					},
					{
						"key": "",
						"title": "↓↓↓签到页面配置↓↓↓",
						"type": "bar-title"
					},
					{
						"key": "signin_image",
						"title": "签到页面顶部图片",
						"type": "file-select",
						"placeholder": "请选择图片",
						"fileType": "image",
						"limit": 1
					},
					{
						"key": "",
						"title": "↓↓↓免费送豆页面配置↓↓↓",
						"type": "bar-title"
					},
					{
						"key": "freeBean",
						"title": "免费金豆数量",
						"type": "text",
						"width": 400
					},
					{
						"key": "receiveTime",
						"title": "免费领取次数",
						"type": "text",
						"width": 400
					},
					{
						"key": "mfld_image",
						"title": "免费领豆图片",
						"type": "file-select",
						"placeholder": "请选择图片",
						"fileType": "image",
						"limit": 1
					},
					// { "key": "payMoney", "title": "支付金额", "type": "text", "width": 400 },
					{
						"key": "",
						"title": "↓↓↓充值说明页面配置↓↓↓",
						"type": "bar-title"
					},
					{
						key: "recharge_instructions",
						title: "充值说明",
						type: "textarea",
						// autosize: { minRows: 4, maxRows: 10 },
						// maxlength: ,
						showWordLimit: true,
					},
					{
						"key": "",
						"title": "↓↓↓小程序简化配置开关↓↓↓",
						"type": "bar-title"
					},
					{
						key: "simplified",
						title: "小程序简化配置开关",
						type: "switch",
						width: 400
					},


					],
					// 表单验证规则
					rules: {
						recharge_instructions: [{
							required: true,
							message: "充值说明必须填写",
							trigger: ['blur', 'change'],
						}],
						// originid: [{
						// 	required: true,
						// 	message: "小程序原始ID必须填写",
						// 	trigger: ['blur', 'change']
						// }],
						appid: [{
							required: true,
							message: "appid必须填写",
							trigger: ['blur', 'change']
						},

						],
						appname: [{
							required: true,
							message: "appname必须填写",
							trigger: ['blur', 'change'],
						}],
						appsecret: [{
							required: true,
							message: "appsecret必须填写",
							trigger: ['blur', 'change'],
						},

						],
						beannumber: [{
							required: true,
							type: "number",
							message: "邀请奖励金豆数必须填写",
							trigger: ['blur', 'change'],
						}],
						signin_reward: [{
							required: true,
							type: "number",
							message: "签到奖励金豆数必须填写",
							trigger: ['blur', 'change'],
						}],
					},
					// add 代表添加 update 代表修改
					formType: "",
					// 是否显示表单的弹窗
					show: false
				}
			},
			// 其他弹窗表单
			formDatas: {},
			// 表单相关结束 -----------------------------------------------------------
		};
	},
	// 监听 - 页面每次【加载时】执行(如：前进)
	onLoad(options = {}) {
		that = this;
		vk = that.vk;
		that.options = options;
		that.init(options);
	},
	// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
	onReady() { },
	// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
	onShow() {
		// if (vk.vuex.get('$user.userInfo.role[0]') != "admin") {
		// 	vk.navigateToLogin();
		// }
	},
	// 监听 - 页面每次【隐藏时】执行(如：返回)
	onHide() { },
	// 函数
	methods: {
		// 页面数据初始化函数
		init(options) {
			originalForms["form1"] = vk.pubfn.copyObject(that.form1);
		},
		// 页面跳转
		pageTo(path) {
			vk.navigateTo(path);
		},
		// 表单重置
		resetForm() {
			vk.pubfn.resetForm(originalForms, that);
		},
		// 搜索
		search() {
			that.$refs.table1.search();
		},
		// 刷新
		refresh() {
			that.$refs.table1.refresh();
		},
		// 获取当前选中的行的数据
		getCurrentRow() {
			return that.$refs.table1.getCurrentRow();
		},
		// 监听 - 行的选中高亮事件
		currentChange(val) {
			that.table1.selectItem = val;
		},
		// 当选择项发生变化时会触发该事件
		selectionChange(list) {
			that.table1.multipleSelection = list;
		},
		batchAdd(item) {
			//如果已存在_id,就是编辑，否则就是新增（此处只能是已_id为判定条件）
			if (this.form1.data.appid != '' && this.form1.data.appid != null) {
				this.form1.data.appid = this.form1.data.appid.trim()
			}
			if (this.form1.data.appsecret != '' && this.form1.data.appsecret != null) {
				this.form1.data.appsecret = this.form1.data.appsecret.trim()
			}
			if (item._id) {
				vk.callFunction({
					url: 'admin/pages/kh/xcxpz/xcxgl/update',
					title: '请求中...',
					data: {
						xcxinfo: this.form1.data
					},
					success: (data) => {
						this.form1.props.show = false; //关闭编辑窗口
						vk.alert('编辑成功');
						this.refresh()
					}
				});
				return;
			} else {
				if (this.form1.data.appid != '' && this.form1.data.appid != null) {
					this.form1.data.appid = this.form1.data.appid.trim()
				}

				if (this.form1.data.appsecret != '' && this.form1.data.appsecret != null) {
					this.form1.data.appsecret = this.form1.data.appsecret.trim()

				}
				vk.callFunction({
					url: 'admin/pages/kh/xcxpz/xcxgl/add',
					title: '请求中...',
					data: {
						xcxinfo: this.form1.data
					},
					success: (data) => {
						this.form1.props.show = false; //关闭编辑窗口
						vk.alert('添加成功');
						this.refresh()
					}
				});

			}
		},
		// 显示添加页面
		addBtn() {
			that.resetForm();
			that.form1.props.action = 'admin/pages/kh/xcxpz/xcxgl/add';
			that.form1.props.formType = 'add';
			that.form1.props.title = '添加';
			that.form1.props.show = true;
		},
		// 显示修改页面
		updateBtn({
			item
		}) {
			console.log("item=", item);

			that.form1.props.action = 'admin/pages/kh/xcxpz/xcxgl/update';
			that.form1.props.formType = 'update';
			that.form1.props.title = '编辑';
			that.form1.props.show = true;
			that.form1.data = item;
		},
		// 删除按钮
		deleteBtn({
			item,
			deleteFn
		}) {
			deleteFn({
				action: "admin/pages/kh/xcxpz/xcxgl/delete",
				data: {
					_id: item._id
				},
			});
		},
		// 监听 - 批量操作的按钮点击事件
		batchBtn(index) {
			switch (index) {
				case 1:
					vk.toast("批量操作按钮1");
					break;
				case 2:
					vk.toast("批量操作按钮2");
					break;
				default:
					break;
			}
		}
	},
	// 监听属性
	watch: {

	},
	// 过滤器
	filters: {

	},
	// 计算属性
	computed: {

	}
};
</script>
<style lang="scss" scoped>
.page-body {}
</style>